package com.wjh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjh.mapper.BasemachineMapper;
import com.wjh.pojo.Basemachine;
import com.wjh.service.BasemachineService;
import com.wjh.service.ChangerecordService;
import com.wjh.service.EnvironmentdataService;
import com.wjh.service.ProducerecordService;
import com.wjh.utils.BeanCopyUtils;
import com.wjh.utils.ResponseResult;
import com.wjh.vo.MachineVo;
import org.apache.commons.collections4.SetUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * (Basemachine)表服务实现类
 *
 * @author makejava
 * @since 2023-12-20 14:16:24
 */
@Service("basemachineService")
public class BasemachineServiceImpl extends ServiceImpl<BasemachineMapper, Basemachine> implements BasemachineService {

    @Resource
    private ChangerecordService changerecordService;

    @Resource
    private ProducerecordService producerecordService;

    @Resource
    private EnvironmentdataService environmentdataService;

    @Override
    public ResponseResult selectList() {
        List<Basemachine> list = list();
        List<MachineVo> machineVos = BeanCopyUtils.copyBeanList(list, MachineVo.class);
        for (MachineVo machineVo : machineVos) {
            machineVo.setProducerecords(producerecordService.queryById(machineVo.getBasemachineid()));
            machineVo.setChangerecords(changerecordService.queryById(machineVo.getBasemachineid()));
            if(machineVo.getBasemachineid() == 110){
                machineVo.setEnvironmentdatas(environmentdataService.list());
            }
        }
        Set<MachineVo> collect = new HashSet<>(machineVos);
        return ResponseResult.okResult(collect);
    }
}
